package com.dyrj.question.service.impl;

import com.dyrj.question.bean.PShoping;
import com.dyrj.question.dao.PShopingMapper;
import com.dyrj.question.service.IPShopingService;
import com.dyrj.utils.DateUtil;
import org.springframework.stereotype.Service;
import com.dyrj.base.system.user.model.SysUser;
import com.dyrj.component.properties.UploadProperties;
import com.dyrj.constant.SysFrameConst;
import com.dyrj.utils.UUIDUtil;
import com.dyrj.vo.PageResultMsg;
import com.dyrj.vo.ResultMsg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j2;
import org.apache.shiro.SecurityUtils;
import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * 商城管理 服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-04-30
 */
@Service
@Log4j2
public class PShopingServiceImpl implements IPShopingService {

    @Resource
    private PShopingMapper mapper;

    @Resource
    private UploadProperties uploadProperties;

    @Override
    public PageResultMsg table(PShoping record) {
        PageInfo<PShoping> list = PageHelper.startPage(record.getOffset(), record.getLimit()).doSelectPageInfo(() -> mapper.selectList(record));
        return new PageResultMsg(SysFrameConst.ResultCode.SUCCESS.CODE, list.getTotal(), list.getList());
    }


    @Override
    public ResultMsg add(PShoping record) {

        String msg = "";
        try {
            record.setAddtime(DateUtil.getDate());
            record.setModtime(DateUtil.getDate());
            mapper.insertSelective(record);
        } catch (Exception e) {
            e.printStackTrace();
            msg = e.getMessage();
        }
        return new ResultMsg(SysFrameConst.ResultCode.SUCCESS.CODE, SysFrameConst.ResultCode.SUCCESS.MESSAGE+msg);
    }


    @Override
    public PShoping info(String id) {
        PShoping ylMmdagl = mapper.selectByPrimaryKey(Integer.parseInt(id));
        return ylMmdagl;
    }

    public ResultMsg update(PShoping record) {
        String msg = "";
        try {
            //PShoping record_db = mapper.se;
            record.setModtime(DateUtil.getDate());
            mapper.updateByPrimaryKeySelective(record);
        } catch (Exception e) {
            e.printStackTrace();
            msg = e.getMessage();
        }
        return new ResultMsg(SysFrameConst.ResultCode.SUCCESS.CODE, SysFrameConst.ResultCode.SUCCESS.MESSAGE + msg);
    }

    @Override
    public ResultMsg delete(String id) {
        mapper.deleteByPrimaryKey(Integer.parseInt(id));
        return new ResultMsg(SysFrameConst.ResultCode.SUCCESS.CODE, SysFrameConst.ResultCode.SUCCESS.MESSAGE);
    }

}
